package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2022/3/19 23:40
 */
@Cmd(code = CrossProtocol.C_WING_ROOM_NEW_MESSAGE, desc = "留言")
public class CrossNewMessageCmd extends CrossCommand {
    private long ownerServerId;
    private long ownerUserId;
    private String content;
    private int noteStyle;
    private List<Long> relativesIdsList;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.NewMessageReqCrossMsg reqMsg = WingRoomProto.NewMessageReqCrossMsg.parseFrom(packet.getBytes());
        ownerServerId = reqMsg.getOwnerServerId();
        ownerUserId = reqMsg.getOwnerUserId();
        content = reqMsg.getContent();
        noteStyle = reqMsg.getNoteStyle();
        relativesIdsList = reqMsg.getRelativesIdsList();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        WingRoomProto.NewMessageCrossReqMsg.Builder crossReqMsg = WingRoomProto.NewMessageCrossReqMsg.newBuilder();
        crossReqMsg.setGuestServerId(serverId);
        crossReqMsg.setGuestUserId(packet.getPlayerId());
        crossReqMsg.setOwnerUserId(ownerUserId);
        crossReqMsg.setContent(content);
        crossReqMsg.setNoteStyle(noteStyle);
        crossReqMsg.addAllRelativesIds(relativesIdsList);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_WING_ROOM_CROSS_NEW_MESSAGE, crossReqMsg);
        MessageHelper.sendPacket(ownerServerId, 0, message);
    }

    @Override
    public void sendData() {

    }
}
